<?php

class FileCsvUpload{
	
	//form 的文件name
	private $form_file = '';

    private	$file 		= null;
	private	$file_data 	= array();
	private	$file_error = '';
	
	function __construct($name){
		$this->form_file = $name;
	}
	
	//上传
	function upload(){
	    //判断文件上传
    	if(empty($_FILES)){
    		//不是上传文件
    		return null;
    	}else{
    		//是上传文件
    		$file = $_FILES[$this->form_file];
    		//文件名
    		$file_name = $file['name'];
    		
    		if($file_name == ''){
    			$this->file_error = '请选择上传文件';
    			return false;
    		}else{
    			$path_info = pathinfo($file_name);
				if(strtolower($path_info['extension']) != 'csv'){
					$this->file_error = '文件格式必需为csv';
					return false;
				}else{
					//文件都正常
					$this->file_data = parse_csv_file($file);
					return true;
				}
    		}
    	}
	}
	
	//获取数据
	function file_data(){
		//去第一行标题
		return $this->file_data;
	}
	
	//获取错误
	function file_error(){
		return $this->file_error;
	}
	
	//去掉第一行
	function remove_header(){
		array_shift($this->file_data);
	}
}

	/*
    	 * array
 		 'task_orders' => 
	    array
	      'name' => string 'task_orders.csv' (length=15)
	      'type' => string 'application/vnd.ms-excel' (length=24)
	      'tmp_name' => string 'C:\Windows\Temp\phpA61E.tmp' (length=27)
	      'error' => int 0
	      'size' => int 98
      */
?>